﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Resources;
using System.Reflection;
using System.Globalization;
using System.Threading;
using System.Drawing;


namespace Yuyi.PluginForJS.Addin
{
    public class MyResourceManager
    {
        public static readonly string strRefresh = "Refresh";
        public static readonly string strCompression = "Compression";
        public static readonly string strOutline = "Outline";
        public static readonly string strFile = "FileList";
        public static readonly string strTools = "Tools";
        public static readonly string strPluginForJS = "PluginForJS";

        private static readonly string resourceName = "Yuyi.PluginForJS.Addin.Resources.addin";

        private static MyResourceManager _instance;
        private ResourceManager ResourceManager;
        private static readonly object lockHelper = new object();

        private MyResourceManager(string name,Assembly asm)
        { 
            this.ResourceManager = new ResourceManager(name,asm);
        }

        public static MyResourceManager Current()
        { 
            if (_instance == null)
            { 
                lock(lockHelper)
                {
                    if (_instance == null)
                    {
                        _instance = new MyResourceManager(resourceName, Assembly.GetExecutingAssembly());
                    }
                }
            }
            return _instance;
        }

        public string GetString(string name,CultureInfo cultureInfo)
        {
            string resourceName;
            if (cultureInfo.TwoLetterISOLanguageName == "zh")
            {
                System.Globalization.CultureInfo parentCultureInfo = cultureInfo.Parent;
                resourceName = String.Concat(parentCultureInfo.Name, name);
            }
            else
            {
                resourceName = String.Concat(cultureInfo.TwoLetterISOLanguageName, name);
            }
            return ResourceManager.GetString(resourceName);
        }

        public Image GetImage(string name)
        {
            return (Image)ResourceManager.GetObject(name);
        }
    }
}
